home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / System / ReqToolsLib / Source / reqtools / palettereq.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-02  |  35.1 KB  |  1,343 lines

  1.  
  2. /* INCLUDES */
  3.  
  4. #include <exec/types.h>
  5. #include <exec/memory.h>
  6. #include <libraries/dos.h>
  7. #include <libraries/dosextens.h>
  8. #include <libraries/gadtools.h>
  9. #include <intuition/icclass.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <gadgets/colorwheel.h>
  15. #include <gadgets/gradientslider.h>
  16. #include <graphics/gfxbase.h>
  17. #include <proto/graphics.h>
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #include <proto/dos.h>
  21. #include <proto/gadtools.h>
  22. #include <proto/utility.h>
  23. #include <proto/alib.h>
  24. #include <proto/colorwheel.h>
  25. #include <clib/macros.h>
  26. #include <string.h>
  27.  
  28. #include <libraries/reqtools.h>
  29. #include <proto/reqtools.h>
  30.  
  31. #include "general.h"
  32. #include "gadstub.h"
  33. #include "boopsigads.h"
  34.  
  35. #include "rtlocale.h"
  36.  
  37. /****************************************************************************************/
  38.  
  39. extern struct ReqToolsBase *ReqToolsBase;
  40.  
  41. /****************************************************************************************/
  42.  
  43. #define COLORWHEEL
  44. #define GRADIENT
  45.  
  46. /****************************************************************************************/
  47.  
  48. extern ULONG ASM LoopReqHandler (ASM_REGPARAM(a1, struct rtHandlerInfo *,));
  49. extern ULONG ASM myGetDisplayInfoData (
  50.         OPT_REGPARAM(a1, UBYTE *,),
  51.     OPT_REGPARAM(d0, unsigned long,),
  52.     OPT_REGPARAM(d1, unsigned long,),
  53.     OPT_REGPARAM(d2, unsigned long,));
  54.  
  55. /****************************************************************************************/
  56.  
  57. #define RED_ID        0        /* DO NOT CHANGE !!! */
  58. #define GREEN_ID    1        /* DO NOT CHANGE !!! */
  59. #define BLUE_ID        2        /* DO NOT CHANGE !!! */
  60.  
  61. #define PALETTE_ID    3
  62. #define COPY_ID        4
  63. #define SWAP_ID        5
  64. #define SPREAD_ID    6
  65. #define OK_ID        7
  66. #define UNDO_ID        8
  67. #define CANCEL_ID    9
  68. #define SLIDER_ID    10
  69. #define WHEEL_ID    11
  70.  
  71. /****************************************************************************************/
  72.  
  73. STRPTR ModeTitles[] =
  74. {
  75.     MSG_COPY_TITLE,
  76.     MSG_SWAP_TITLE,
  77.     MSG_SPREAD_TITLE
  78. };
  79.  
  80. /****************************************************************************************/
  81.  
  82. #define MODE_TITLE_OFFSET    COPY_ID
  83.  
  84.  
  85. #define LOWGRADPENS        4
  86. #define HIGHGRADPENS        8
  87. #define FREEFORHIGH        32
  88.  
  89. #define NO_TITLE        ( ( STRPTR ) ~0 )
  90.  
  91. /****************************************************************************************/
  92.  
  93. extern struct Library         *GadToolsBase;
  94. extern struct IntuitionBase     *IntuitionBase;
  95. extern struct GfxBase         *GfxBase;
  96.  
  97. extern struct TextAttr         topaz80;
  98.  
  99. /****************************************************************************************/
  100.  
  101. typedef struct RealHandlerInfo            GlobData;
  102.  
  103. struct RealHandlerInfo
  104. {
  105.     LONG                 (*func)();         /* private */
  106.     ULONG                 rthi_WaitMask;
  107.     ULONG                 rthi_DoNotWait;
  108.  
  109.     /* PRIVATE */
  110.     ULONG                 cols[3];    /* DO NOT MOVE, see cols offset in misc.asm */
  111.     struct ViewPort             *vp;        /* DO NOT MOVE, see vp offset in misc.asm */
  112.     union
  113.     {                            /* DO NOT MOVE, see offsets in misc.asm */
  114.     struct
  115.     {
  116.         ULONG             red, green, blue;
  117.     }                 bits;
  118.     ULONG                 colbits[3];
  119.     }                     col;
  120.     struct NewWindow             newpalwin;
  121.     struct KeyButtonInfo         buttoninfo;
  122.     struct Screen             *scr, *frontscr;
  123.     struct Gadget             *colgad[3], *palgad;
  124.     struct Window             *palwin, *win, *prwin;
  125.     struct ColorMap             *cm;
  126.     struct TextAttr             font;
  127.     struct TextFont             *reqfont;
  128.     struct DrawInfo             *drinfo;
  129.     struct Image             labelimages;
  130.     struct rtReqInfo             *reqinfo;
  131.     struct Hook             *imsghook, backfillhook;
  132.     struct Catalog             *catalog;
  133.     struct IntuiText            itxt;
  134.     long                 color, coldepth, colcount, reqpos, leftedge, topedge;
  135.     int                 waitpointer, lockwindow, shareidcmp, noscreenpop;
  136.     int                 fontwidth, fontheight, mode, os30, maxcolval[3];
  137.     char                 key[3], palettekey;
  138.     APTR                 colormap, undomap;
  139.     APTR                 visinfo, winlock;
  140.     WORD                zoom[4];
  141.  
  142. #ifdef COLORWHEEL
  143.     /* Color wheel */
  144.     struct Library             *ColorWheelBase;
  145.     struct Library             *GradientSliderBase;
  146.     struct ColorWheelRGB         wheel_rgb;
  147.     struct ColorWheelHSB         wheel_hsb;
  148.     struct Gadget             *wheel;
  149.     struct Gadget             *wheel_slider;
  150.     ULONG                 wheel_colortable[3];
  151.  
  152. #ifdef GRADIENT
  153.     UWORD                wheel_pens[ HIGHGRADPENS + 1 ];
  154.     UWORD                numgradpens;
  155. #endif
  156.     WORD                dowheel, fancywheel;
  157.     Point                screenres;
  158. #endif
  159. };
  160.  
  161. /****************************************************************************************/
  162.  
  163. #define redbits            col.bits.red
  164. #define greenbits        col.bits.green
  165. #define bluebits        col.bits.blue
  166.  
  167. #define ThisProcess()        ( ( struct Process * ) FindTask( NULL ) )
  168.  
  169. /****************************************************************************************/
  170.  
  171. extern ULONG ASM MakeColVal (ASM_REGPARAM(d0, ULONG,), ASM_REGPARAM(d4, ULONG,));
  172. extern void REGARGS SpreadColors (GlobData *, int, int, ULONG *);
  173.  
  174. static int REGARGS SetupPalWindow (GlobData *, char *);
  175. static void REGARGS SelectColor (GlobData *, int);
  176. static void REGARGS FreeAll (GlobData *);
  177. static void REGARGS SetColor (GlobData *, int, ULONG *);
  178. static void REGARGS SetWheelColor (GlobData *, struct TagItem * );
  179. static void REGARGS UpdateWheel( GlobData *, ULONG * );
  180. static void REGARGS RestorePaletteFreeAll (GlobData *);
  181. static void REGARGS DoColorShortcut (GlobData *, int, int, int);
  182. static LONG ASM SAVEDS PalReqHandler (
  183.     REGPARAM(a1, struct RealHandlerInfo *,),
  184.     REGPARAM(d0, ULONG,),
  185.     REGPARAM(a0, struct TagItem *,));
  186.  
  187. /****************************************************************************************/
  188.  
  189. #ifdef COLORWHEEL
  190. #define ColorWheelBase        glob->ColorWheelBase
  191. #define GradientSliderBase    glob->GradientSliderBase
  192. #endif
  193.  
  194.  
  195. /****************************************************************************************/
  196.  
  197. #if !USE_ASM_FUNCS
  198.  
  199. /****************************************************************************************/
  200.  
  201. ULONG MakeColVal(ULONG val, ULONG bits)                          
  202. {
  203.     ULONG val2;
  204.     
  205.     val2 = val << (32 - bits);
  206.     val = val2;
  207.     do
  208.     {
  209.         val2 >>= bits;
  210.     val |= bits;
  211.     } while(val2);
  212.     
  213.     return val;
  214. }
  215.  
  216. /****************************************************************************************/
  217.  
  218. void REGARGS SpreadColors (GlobData *glob, int from, int to, ULONG *rgb2)
  219. {
  220.     LONG colstep;
  221.     LONG step[3];
  222.     LONG rgb[3];
  223.     WORD actcol, steps, gun;
  224.     
  225.     colstep = 1;
  226.  
  227.     steps = to - from;
  228.     if (!steps) return;
  229.  
  230.     if (steps < 0)
  231.     {
  232.         steps = -steps;
  233.     colstep = -1;
  234.     }
  235.     
  236.     for(gun = 0; gun < 3; gun++)
  237.     {
  238.         LONG diff = rgb2[gun] - glob->cols[gun];
  239.     step[gun] = (diff << 16L) / steps;
  240.     rgb[gun] = glob->cols[gun] << 16;
  241.     }
  242.     
  243.     actcol = from;
  244.            
  245.     for(actcol = from;
  246.         actcol != to;
  247.         actcol += colstep, rgb[0] += step[0], rgb[1] += step[1], rgb[2] += step[2])
  248.     {
  249.         ULONG red   = (((ULONG)rgb[0]) + 0x8000) >> 16;
  250.     ULONG green = (((ULONG)rgb[1]) + 0x8000) >> 16;
  251.     ULONG blue  = (((ULONG)rgb[2]) + 0x8000) >> 16;
  252.     
  253.     if (GfxBase->LibNode.lib_Version >= 39)
  254.     {
  255.         SetRGB32(glob->vp, actcol, MakeColVal(red, glob->col.colbits[0]),
  256.                            MakeColVal(green, glob->col.colbits[1]),
  257.                        MakeColVal(blue, glob->col.colbits[2]));
  258.     }
  259.     else
  260.     {
  261.         SetRGB4(glob->vp, actcol, red, green, blue);
  262.     }
  263.         
  264.     }
  265.     
  266. }
  267.  
  268. /****************************************************************************************/
  269.  
  270. #endif /* !USE_ASM_FUNCS */
  271.  
  272. /****************************************************************************************/
  273.  
  274. #ifdef DO_CM_DEPTH
  275. static int
  276. ColBits( int num )
  277. {
  278.     int    i, j;
  279.  
  280.     if( num < 2 )
  281.     {
  282.     return( 1 );
  283.     }
  284.  
  285.     for( i = 1, j = 4; i <= 8; ++i, j <<= 1 )
  286.     {
  287.     if( j > num )
  288.     {
  289.         return( i );
  290.     }
  291.     }
  292.  
  293.     return( 8 );
  294. }
  295. #endif
  296.  
  297. /****************************************************************************************/
  298.  
  299. LONG ASM SAVEDS PaletteRequestA (
  300.     REGPARAM(a2, char *, title),
  301.     REGPARAM(a3, struct rtReqInfo *, reqinfo),
  302.     REGPARAM(a0, struct TagItem *, taglist))
  303. {
  304.     GlobData         *glob;
  305.     struct DisplayInfo     displayinfo;
  306.     struct TagItem     *tag, *tstate;
  307.     struct TextFont     *deffont = NULL;
  308.     struct TextAttr     *fontattr = NULL;
  309.     struct Locale     *locale = NULL;
  310.     char         *pubname = NULL;
  311.     ULONG         tagdata, reqhandler = FALSE;
  312.  
  313.     if (!(glob = AllocVec (sizeof(GlobData), MEMF_PUBLIC|MEMF_CLEAR)))
  314.     return (-1);
  315.  
  316.     glob->os30 = (GfxBase->LibNode.lib_Version >= 39);
  317.     glob->color = 1;
  318.     glob->reqpos = REQPOS_DEFAULT;
  319.     
  320.     if ((glob->reqinfo = reqinfo))
  321.     {
  322.     glob->reqpos = reqinfo->ReqPos;
  323.     glob->leftedge = reqinfo->LeftOffset;
  324.     glob->topedge = reqinfo->TopOffset;
  325.     deffont = reqinfo->DefaultFont;
  326.     glob->waitpointer = reqinfo->WaitPointer;
  327.     glob->lockwindow = reqinfo->LockWindow;
  328.     glob->shareidcmp = reqinfo->ShareIDCMP;
  329.     glob->imsghook = reqinfo->IntuiMsgFunc;
  330.     }
  331.  
  332.     /* parse tags */
  333.     tstate = taglist;
  334.     while ((tag = NextTagItem ((const struct TagItem **)&tstate)))
  335.     {
  336.     tagdata = tag->ti_Data;
  337.     if (tag->ti_Tag > RT_TagBase)
  338.     {
  339.         switch (tag->ti_Tag)
  340.         {
  341.         case RT_Window:        glob->prwin = (struct Window *)tagdata; break;
  342.         case RT_ReqPos:        glob->reqpos = tagdata; break;
  343.         case RT_LeftOffset:    glob->leftedge = tagdata; break;
  344.         case RT_TopOffset:    glob->topedge = tagdata; break;
  345.         case RT_PubScrName:    pubname = (char *)tagdata; break;
  346.         case RT_Screen:        glob->scr = (struct Screen *)tagdata; break;
  347.         case RT_ReqHandler:    *(APTR *)tagdata = glob;
  348.                     reqhandler = TRUE;
  349.                     break;
  350.         case RT_DefaultFont:    deffont = (struct TextFont *)tagdata; break;
  351.         case RT_WaitPointer:    glob->waitpointer = tagdata; break;
  352.         case RT_ShareIDCMP:    glob->shareidcmp = tagdata; break;
  353.         case RT_LockWindow:    glob->lockwindow = tagdata; break;
  354.         case RT_ScreenToFront:    glob->noscreenpop = !tagdata; break;
  355.         case RT_TextAttr:    fontattr = (struct TextAttr *)tagdata; break;
  356.         case RT_IntuiMsgFunc:    glob->imsghook = (struct Hook *)tagdata; break;
  357.         case RT_Locale:        locale = (struct Locale *)tagdata; break;
  358.         case RTPA_Color:    glob->color = tagdata; break;
  359.         }
  360.     }
  361.     }
  362.  
  363.     glob->catalog = RT_OpenCatalog (locale);
  364.  
  365.     if (!glob->prwin || !glob->prwin->UserPort ||
  366.         (glob->prwin->UserPort->mp_SigTask != ThisProcess()))
  367.     glob->shareidcmp = FALSE;
  368.  
  369.     if (!(glob->scr = GetReqScreen (&glob->newpalwin, &glob->prwin, glob->scr, pubname)))
  370.     return (-1);
  371.     
  372.     glob->vp = &glob->scr->ViewPort;
  373.     glob->cm = glob->vp->ColorMap;
  374.  
  375.     if (!(glob->coldepth = GetVpCM (glob->vp, &glob->colormap)) ||
  376.         !GetVpCM (glob->vp, &glob->undomap))
  377.     {
  378.     FreeAll (glob);
  379.     return (-1);
  380.     }
  381.  
  382.     glob->colcount = (1 << glob->coldepth);
  383.     glob->newpalwin.Screen = glob->scr;
  384.  
  385.     if (fontattr)
  386.         glob->font = *fontattr;
  387.     else
  388.         glob->font = *glob->scr->Font;
  389.  
  390.     glob->redbits = glob->greenbits = glob->bluebits = 4;
  391.     if (glob->os30)
  392.     {
  393.     if (myGetDisplayInfoData ((UBYTE *)&displayinfo, sizeof (struct DisplayInfo),
  394.                   DTAG_DISP, GetVPModeID (glob->vp)) > 0)
  395.     {
  396.         glob->redbits = displayinfo.RedBits;
  397.         glob->greenbits = displayinfo.GreenBits;
  398.         glob->bluebits = displayinfo.BlueBits;
  399. #ifdef COLORWHEEL
  400.  
  401. #ifdef _AROS
  402. #warning DisplayInfo.Resolution does not seem to have correct/any values yet in AROS
  403.         glob->screenres.x = glob->screenres.y = 22;
  404. #else
  405.         glob->screenres = displayinfo.Resolution;
  406. #endif
  407.  
  408. #endif
  409.     }
  410.     }
  411.     
  412.     glob->maxcolval[RED_ID] = (1 << glob->redbits) - 1;
  413.     glob->maxcolval[GREEN_ID] = (1 << glob->greenbits) - 1;
  414.     glob->maxcolval[BLUE_ID] = (1 << glob->bluebits) - 1;
  415.  
  416.     if (!(glob->visinfo = GetVisualInfoA (glob->scr, NULL)) ||
  417.         !(glob->drinfo = GetScreenDrawInfo (glob->scr)))
  418.     {
  419.     FreeAll (glob);
  420.     return (-1);
  421.     }
  422.  
  423. #ifdef COLORWHEEL
  424.     {
  425.     struct ReqToolsPrefs *prefs;
  426.  
  427.     prefs = rtLockPrefs();
  428.     glob->dowheel = ( prefs->Flags & RTPRF_DOWHEEL ) && glob->os30;
  429.     glob->fancywheel = glob->dowheel && ( prefs->Flags & RTPRF_FANCYWHEEL );
  430.     rtUnlockPrefs();
  431.     }
  432.  
  433.     if( glob->dowheel )
  434.     {
  435.     if ((ColorWheelBase = OpenLibrary ("gadgets/colorwheel.gadget", 39)))
  436.     {
  437.         GradientSliderBase = OpenLibrary ("gadgets/gradientslider.gadget", 39);
  438.     }
  439.     }
  440. #endif
  441.  
  442.     SelectColor (glob, glob->color);
  443.  
  444. retryopenwin:
  445.     if (!(glob->reqfont = GetReqFont (&glob->font, deffont, &glob->fontheight,
  446.                               &glob->fontwidth, glob->os30)))
  447.     {
  448.     FreeAll (glob);
  449.     return (-1);
  450.     }
  451.  
  452.     if (!SetupPalWindow (glob, title))
  453.     {
  454.     if( glob->dowheel )
  455.     {
  456.         glob->dowheel = FALSE;
  457. #ifdef COLORWHEEL
  458.         DisposeObject( glob->wheel );
  459.         DisposeObject( glob->wheel_slider );
  460.         glob->wheel = NULL;
  461.         glob->wheel_slider = NULL;
  462.         CloseLibrary( ColorWheelBase );
  463.         CloseLibrary( GradientSliderBase );
  464.         ColorWheelBase = NULL;
  465.         GradientSliderBase = NULL;
  466. #endif
  467.         goto retryopenwin;
  468.     }
  469.  
  470.     if (glob->font.ta_YSize > 8)
  471.     {
  472.         glob->font = topaz80;
  473.         CloseFont (glob->reqfont);
  474.         goto retryopenwin;
  475.     }
  476.     
  477.     FreeAll (glob);
  478.     return (-1);
  479.     }
  480.  
  481. #ifdef COLORWHEEL
  482.     if( glob->fancywheel )
  483.     {
  484.     /* Try to get a fresh undo color map (in case the wheel allocates some) */
  485.     RefreshVpCM( glob->vp, glob->undomap );
  486.  
  487.     /* And make sure selected color still is correct */
  488.     SelectColor( glob, glob->color );
  489.     }
  490. #endif
  491.  
  492.     glob->winlock = DoLockWindow (glob->prwin, glob->lockwindow, NULL, TRUE);
  493.     DoWaitPointer (glob->prwin, glob->waitpointer, TRUE);
  494.  
  495.     glob->frontscr = IntuitionBase->FirstScreen;
  496.     DoScreenToFront (glob->scr, glob->noscreenpop, TRUE);
  497.  
  498.     /* fill in RealHandlerInfo */
  499.     glob->func = (LONG (*)())PalReqHandler;
  500.     glob->rthi_WaitMask = (1 << glob->palwin->UserPort->mp_SigBit);
  501.  
  502.     if (reqhandler) return (CALL_HANDLER);
  503.     
  504.     return ((LONG)LoopReqHandler ((struct rtHandlerInfo *)glob));
  505. }
  506.  
  507. /****************************************************************************************/
  508.  
  509. static LONG ASM SAVEDS PalReqHandler (
  510.     REGPARAM(a1, struct RealHandlerInfo *, glob),
  511.     REGPARAM(d0, ULONG, sigs),
  512.     REGPARAM(a0, struct TagItem *, taglist))
  513. {
  514.     struct IntuiMessage *palmsg;
  515.     struct Gadget     *gad;
  516.     struct TagItem     *tag, *tstate;
  517.     ULONG         rgb[3], rgbcol;
  518.     ULONG         tagdata, class;
  519.     UWORD         code, qual;
  520.     int         i, gadid, shifted, alt;
  521.     char         key;
  522.  
  523.     /* uncomment if sigs is no longer ignored */
  524.     //if (glob->rthi_DoNotWait) sigs = 0;
  525.  
  526.     /* parse tags */
  527.     tstate = taglist;
  528.     while ((tag = NextTagItem ((const struct TagItem **)&tstate)))
  529.     {
  530.     tagdata = tag->ti_Data;
  531.     if (tag->ti_Tag > RT_TagBase)
  532.     {
  533.         switch (tag->ti_Tag)
  534.         {
  535.         case RTRH_EndRequest:
  536.             if (tagdata == REQ_OK)
  537.             {
  538.             FreeAll (glob);
  539.             return (0);
  540.             }
  541.             RestorePaletteFreeAll (glob);
  542.             return (-1);
  543.         }
  544.     }
  545.     }
  546.  
  547.     while ((palmsg = GetWin_GT_Msg (glob->palwin, glob->imsghook, glob->reqinfo)))
  548.     {
  549.     class = palmsg->Class;
  550.     code = palmsg->Code;
  551.     qual = palmsg->Qualifier;
  552.     gad = (struct Gadget *)palmsg->IAddress;
  553.     Reply_GT_Msg (palmsg);
  554.     
  555.     switch (class)
  556.     {
  557.         case IDCMP_REFRESHWINDOW:
  558.         GT_BeginRefresh (glob->palwin);
  559.         GT_EndRefresh (glob->palwin, TRUE);
  560.         break;
  561.         
  562.         case IDCMP_CLOSEWINDOW:
  563.         RestorePaletteFreeAll (glob);
  564.         return (-1);
  565.         
  566.         case IDCMP_MOUSEMOVE:
  567.         case IDCMP_GADGETDOWN:
  568.         if (gad->GadgetID <= BLUE_ID)
  569.         {
  570.             glob->cols[gad->GadgetID] = code;
  571.             SetColor (glob, glob->color, glob->cols);
  572. #ifdef COLORWHEEL
  573.             UpdateWheel( glob, glob->cols );
  574. #endif
  575.         }
  576.         break;
  577.         
  578.         case IDCMP_RAWKEY:
  579.         case IDCMP_GADGETUP:
  580.         if (class == IDCMP_RAWKEY)
  581.         {
  582.             if (!(gadid = CheckGadgetKey (code, qual, &key, &glob->buttoninfo)))
  583.             {
  584.             /* key press was not for gadget, so check other cases */
  585.             shifted = qual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT);
  586.             alt = qual & (IEQUALIFIER_LALT|IEQUALIFIER_RALT);
  587.             if (key == glob->key[RED_ID])
  588.                 DoColorShortcut (glob, RED_ID, shifted, alt);
  589.             else if (key == glob->key[GREEN_ID])
  590.                 DoColorShortcut (glob, GREEN_ID, shifted, alt);
  591.             else if (key == glob->key[BLUE_ID])
  592.                 DoColorShortcut (glob, BLUE_ID, shifted, alt);
  593.             else if (key == glob->palettekey)
  594.             {
  595.                 code = glob->color;
  596.                 if (!shifted) 
  597.                 {
  598.                 code++;
  599.                 if (code >= glob->colcount) code = 0;
  600.                 }
  601.                 else
  602.                 {
  603.                 if (code <= 0) code = glob->colcount;
  604.                 code--;
  605.                 }
  606.                 myGT_SetGadgetAttrs (glob->palgad, glob->palwin, NULL,
  607.                          GTPA_Color, code, TAG_END);
  608.                 gadid = PALETTE_ID;
  609.                 glob->mode = 0;
  610.             }
  611.             
  612.             }
  613.             
  614.         } /* if (class == IDCMP_RAWKEY) */
  615.         else gadid = gad->GadgetID;
  616.         
  617.         if (gadid) switch (gadid)
  618.         {
  619.             case CANCEL_ID:
  620.             RestorePaletteFreeAll (glob);
  621.             return (-1);
  622.             
  623.             case OK_ID:
  624.             code = glob->color;
  625.             FreeAll (glob);
  626.             return ((LONG)code);
  627.             
  628.             case PALETTE_ID:
  629.             RefreshVpCM (glob->vp, glob->undomap);
  630.             
  631.             if (!glob->os30)
  632.             {
  633.                 rgbcol = GetRGB4 (glob->cm, code);
  634.                 for (i = 2; i >= 0; i--)
  635.                 {
  636.                 rgb[i] = rgbcol & 0xf;
  637.                 rgbcol >>= 4;
  638.                 }
  639.             }
  640.             else
  641.             {
  642.                 GetRGB32 (glob->cm, code, 1, rgb);
  643.                 rgb[0] >>= (32 - glob->redbits);
  644.                 rgb[1] >>= (32 - glob->greenbits);
  645.                 rgb[2] >>= (32 - glob->bluebits);
  646.             }
  647.             
  648.             switch (glob->mode)
  649.             {
  650.                 case SWAP_ID:
  651.                     SetColor (glob, glob->color, rgb);
  652.                 case COPY_ID:
  653.                     SetColor (glob, code, glob->cols);
  654.                     break;
  655.                 case SPREAD_ID:
  656.                     SpreadColors (glob, glob->color, code, rgb);
  657.                     break;
  658.             }
  659.             
  660.             SelectColor (glob, code);
  661.             glob->mode = 0;
  662.             SetWindowTitles( glob->palwin, glob->newpalwin.Title, NO_TITLE );
  663. #ifdef COLORWHEEL
  664.             UpdateWheel( glob, glob->cols );
  665. #endif
  666.             break;
  667.                 
  668.             case UNDO_ID:
  669.             LoadCMap (glob->vp, glob->undomap);
  670.             SelectColor (glob, glob->color);
  671. #ifdef COLORWHEEL
  672.             UpdateWheel( glob, glob->cols );
  673. #endif
  674.             break;
  675.  
  676.             default:
  677.             if( ( gadid == SWAP_ID ) || ( gadid == COPY_ID ) || ( gadid == SPREAD_ID ) )
  678.             {
  679.                 glob->mode = gadid;
  680.                 SetWindowTitles( glob->palwin, GetStr( glob->catalog, ModeTitles[ gadid - MODE_TITLE_OFFSET ] ), NO_TITLE );
  681.             }
  682.  
  683.             break;
  684.                 
  685.         } /* if (gadid) switch (gadid) */
  686.         break;
  687.  
  688. #ifdef COLORWHEEL
  689.         case IDCMP_IDCMPUPDATE:
  690.         SetWheelColor( glob, ( struct TagItem * ) gad );
  691.         break;
  692. #endif
  693.     }
  694.  
  695.     } /* while ((palmsg = GetWin_GT_Msg (glob->palwin, glob->imsghook, glob->reqinfo))) */
  696.     
  697.     return (CALL_HANDLER);
  698. }
  699.  
  700. /****************************************************************************************/
  701.  
  702. static void REGARGS DoColorShortcut (GlobData *glob, int id, int shifted, int alt)
  703. {
  704.     int t = glob->cols[id];
  705.  
  706.     if (shifted)
  707.     {
  708.     if (alt) t -= 8; else t--;
  709.     if (t < 0) t = 0;
  710.     }
  711.     else
  712.     {
  713.     if (alt) t += 8; else t++;
  714.     if (t >= glob->maxcolval[id]) t = glob->maxcolval[id];
  715.     }
  716.     
  717.     glob->cols[id] = t;
  718.     SetColor (glob, glob->color, glob->cols);
  719.     SelectColor (glob, glob->color);
  720. }
  721.  
  722. /****************************************************************************************/
  723.  
  724. static void REGARGS SetColor (GlobData *glob, int col, ULONG *rgb)
  725. {
  726.     if( !glob->os30 )
  727.     {
  728.     SetRGB4( glob->vp, col, rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] );
  729.     }
  730.     else
  731.     {
  732.     SetRGB32( glob->vp, col,
  733.         MakeColVal( rgb[ 0 ], glob->redbits ),
  734.         MakeColVal( rgb[ 1 ], glob->greenbits ),
  735.         MakeColVal( rgb[ 2 ], glob->bluebits) );
  736.     }
  737. }
  738.  
  739. /****************************************************************************************/
  740.  
  741. #ifdef COLORWHEEL
  742.  
  743. /****************************************************************************************/
  744.  
  745. #ifdef GRADIENT
  746.  
  747. /****************************************************************************************/
  748.  
  749. static void REGARGS
  750. UpdateGrad( GlobData *glob )
  751. {
  752.     if( glob->numgradpens )
  753.     {
  754.     LONG    i;
  755.  
  756.     GetAttr( WHEEL_HSB, (Object *)glob->wheel, ( IPTR * ) &glob->wheel_hsb );
  757.  
  758.     for( i = 0; i < glob->numgradpens; ++i )
  759.     {
  760.         glob->wheel_hsb.cw_Brightness = 0xffffffff - ( ( 0xffffffff / ( glob->numgradpens - 1 ) ) * i );
  761.         ConvertHSBToRGB( &glob->wheel_hsb, &glob->wheel_rgb );
  762.         SetRGB32( &glob->scr->ViewPort, glob->wheel_pens[ i ],
  763.             glob->wheel_rgb.cw_Red, glob->wheel_rgb.cw_Green,
  764.             glob->wheel_rgb.cw_Blue );
  765.     }
  766.     }
  767. }
  768.  
  769. /****************************************************************************************/
  770.  
  771. #endif
  772.  
  773. /****************************************************************************************/
  774.  
  775. static void REGARGS
  776. UpdateWheel( GlobData *glob, ULONG *cols )
  777. {
  778.     if( glob->wheel )
  779.     {
  780.     glob->wheel_rgb.cw_Red   = MakeColVal( cols[ 0 ], glob->redbits );
  781.     glob->wheel_rgb.cw_Green = MakeColVal( cols[ 1 ], glob->greenbits );
  782.     glob->wheel_rgb.cw_Blue  = MakeColVal( cols[ 2 ], glob->bluebits );
  783.  
  784.     SetGadgetAttrs( glob->wheel, glob->palwin, NULL, WHEEL_RGB, &glob->wheel_rgb,
  785.                              TAG_DONE );
  786.  
  787. #ifdef GRADIENT
  788.     UpdateGrad( glob );
  789. #endif
  790.     }
  791. }
  792.  
  793. /****************************************************************************************/
  794.  
  795. static void REGARGS
  796. SetWheelColor( GlobData *glob, struct TagItem *tag )
  797. {
  798.     if( glob->wheel )
  799.     {
  800.     ULONG i;
  801.  
  802.     GetAttr( WHEEL_HSB, (Object *)glob->wheel, ( IPTR * ) &glob->wheel_hsb );
  803.     ConvertHSBToRGB( &glob->wheel_hsb, &glob->wheel_rgb );
  804.     glob->cols[ RED_ID ]    = glob->wheel_rgb.cw_Red >> ( 32 - glob->redbits );
  805.     glob->cols[ GREEN_ID ]    = glob->wheel_rgb.cw_Green >> ( 32 - glob->greenbits );
  806.     glob->cols[ BLUE_ID ]    = glob->wheel_rgb.cw_Blue >> ( 32 - glob->bluebits );
  807.     SetColor( glob, glob->color, glob->cols );
  808.  
  809.     for( i = 0; i < 3; ++i )
  810.     {
  811.         if( glob->colgad[ i ] )
  812.         {
  813.         myGT_SetGadgetAttrs( glob->colgad[ i ], glob->palwin, NULL, GTSL_Level,    glob->cols[ i ],
  814.                                         TAG_END );
  815.         }
  816.     }
  817.  
  818. #ifdef GRADIENT
  819.     UpdateGrad( glob );
  820. #endif
  821.     }
  822. }
  823.  
  824. /****************************************************************************************/
  825.  
  826. #endif
  827.  
  828. /****************************************************************************************/
  829.  
  830. static void REGARGS SelectColor (GlobData *glob, int col)
  831. {
  832.     ULONG rgb[3], rgbcol;
  833.     int i;
  834.  
  835.     if (!glob->os30) rgbcol = GetRGB4 (glob->cm, col);
  836.     else GetRGB32 (glob->cm, col, 1, rgb);
  837.     
  838.     for (i = 2; i >= 0; i--)
  839.     {
  840.     if (!glob->os30)
  841.     {
  842.         glob->cols[i] = rgbcol & 0xF;
  843.         rgbcol >>= 4;
  844.     }
  845.     else glob->cols[i] = rgb[i] >> (32 - glob->col.colbits[i]);
  846.     
  847.     if (glob->colgad[i])
  848.         myGT_SetGadgetAttrs (glob->colgad[i], glob->palwin, NULL,
  849.                      GTSL_Level, glob->cols[i], TAG_END);
  850.     }
  851.     
  852.     glob->color = col;
  853. }
  854.  
  855. /****************************************************************************************/
  856.  
  857. static void REGARGS RestorePaletteFreeAll (GlobData *glob)
  858. {
  859.     LoadCMap (glob->vp, glob->colormap);
  860.     FreeAll (glob);
  861. }
  862.  
  863. /****************************************************************************************/
  864.  
  865. static void REGARGS FreeAll (GlobData *glob)
  866. {
  867. #ifdef COLORWHEEL
  868. #ifdef GRADIENT
  869.     LONG    i;
  870. #endif
  871. #endif
  872.     if (glob->newpalwin.Type == PUBLICSCREEN) UnlockPubScreen (NULL, glob->scr);
  873.     DoScreenToFront (glob->frontscr, glob->noscreenpop, FALSE);
  874.     
  875.     if (glob->palwin)
  876.     {
  877.     DoLockWindow (glob->prwin, glob->lockwindow, glob->winlock, FALSE);
  878.     DoWaitPointer (glob->prwin, glob->waitpointer, FALSE);
  879.     DoCloseWindow (glob->palwin, glob->shareidcmp);
  880.     }
  881.     
  882.     RT_CloseCatalog (glob->catalog);
  883.     my_FreeGadgets (glob->buttoninfo.glist);
  884.     my_FreeLabelImages (&glob->labelimages);
  885.  
  886. #ifdef COLORWHEEL
  887.     DisposeObject (glob->wheel);
  888.     DisposeObject (glob->wheel_slider);
  889.     
  890. #ifdef GRADIENT
  891.     if( glob->numgradpens )
  892.     {
  893.     for( i = 0; glob->wheel_pens[ i ] != (UWORD)~0; i++ )
  894.     {
  895.         ReleasePen( glob->scr->ViewPort.ColorMap, glob->wheel_pens[ i ] );
  896.     }
  897.     }
  898. #endif
  899.  
  900.     CloseLibrary (GradientSliderBase);
  901.     CloseLibrary (ColorWheelBase);
  902. #endif
  903.  
  904.     FreeVisualInfo (glob->visinfo);
  905.     
  906.     if (glob->drinfo) FreeScreenDrawInfo (glob->scr, glob->drinfo);
  907.     if (glob->reqfont) CloseFont (glob->reqfont);
  908.     
  909.     FreeVpCM (glob->vp, glob->colormap, FALSE);
  910.     FreeVpCM (glob->vp, glob->undomap, FALSE);
  911.     FreeVec (glob);
  912. }
  913.  
  914. /****************************************************************************************/
  915.  
  916. char *colstr[] = { MSG_RED, MSG_GREEN, MSG_BLUE };
  917. char *gadtxt[] = { MSG_COPY, MSG_SWAP, MSG_SPREAD, MSG_OK, MSG_UNDO, MSG_CANCEL };
  918.  
  919. /****************************************************************************************/
  920.  
  921. static int REGARGS SetupPalWindow (GlobData *glob, char *title)
  922. {
  923.     struct NewGadget     ng;
  924.     struct Gadget     *gad;
  925.     struct Image     *img;
  926.     int         val, i, top, buttonheight, winheight;
  927.     int         spacing, scrwidth, scrheight, maxwidth;
  928.     int         winwidth, width1, width2, reqpos, levelwidth;
  929. #ifdef COLORWHEEL
  930.     int         wheelwidth, wheelheight, wheeltopoff;
  931. #endif
  932.     int         wheeloff = 0;
  933.     int         leftoff, rightoff;
  934.     ULONG         gadlen[6], gadpos[6];
  935.     char         *str, *string[6];
  936.  
  937.  
  938.     spacing = rtGetVScreenSize (glob->scr, (ULONG *)&scrwidth, (ULONG *)&scrheight);
  939.     leftoff = glob->scr->WBorLeft + 5;
  940.     rightoff = glob->scr->WBorRight + 5;
  941.  
  942.     top = (glob->scr->WBorTop + glob->scr->Font->ta_YSize + 1) + spacing / 2 + 1;
  943.     glob->itxt.ITextFont = &glob->font;
  944.  
  945. #ifdef COLORWHEEL
  946.     wheeltopoff = top;
  947. #endif
  948.  
  949.     width1 = width2 = 0;
  950.     
  951.     for (i = 0; i < 6; i++)
  952.     {
  953.     string[i] = GetStr (glob->catalog, gadtxt[i]);
  954.     val = StrWidth_noloc (&glob->itxt, string[i]) + 16;
  955.     if (i < 3)
  956.     {
  957.         if (val > width1) width1 = val;
  958.     }
  959.     else
  960.     {
  961.         if (val > width2) width2 = val;
  962.     }
  963.     }
  964.  
  965.     for (i = 0; i < 3; i++) gadlen[i] = width1;
  966.     for (i = 3; i < 6; i++) gadlen[i] = width2;
  967.  
  968.     width1 *= 3;
  969.     width2 *= 3;
  970.  
  971.     winwidth = (leftoff + rightoff) + 25 + width1 + 2 * 8;
  972.     val = (leftoff + rightoff) + width2 + 2 * 8;
  973.     if (val > winwidth) winwidth = val;
  974.     if (winwidth < 256) winwidth = 256;
  975.  
  976.     val = glob->fontheight * 2 + 4;
  977. #ifdef _AROS
  978.     val += 5;
  979. #endif
  980.  
  981.     if (glob->colcount >= 64) val *= 2;
  982.     if (glob->colcount >= 128) val *= 2;
  983.  
  984.  
  985. #ifdef COLORWHEEL
  986.     if( glob->dowheel && glob->screenres.x && glob->screenres.y && ColorWheelBase && GradientSliderBase )
  987.     {
  988.     LONG    maxheight = 120;
  989.  
  990.     if( scrheight > 600 )
  991.     {
  992.         maxheight = 160;
  993.     }
  994.     else if( scrheight < 300 )
  995.     {
  996.         maxheight = 75;
  997.     }
  998.  
  999.     wheelheight = val + glob->fontheight * 4 + 6 + 3 + spacing * 3;
  1000.  
  1001.     if( wheelheight > maxheight )
  1002.     {
  1003.         wheelheight = maxheight;
  1004.     }
  1005.  
  1006.     #ifndef _AROS
  1007.     #if 1
  1008.     #warning Changed, because gcc produced wrong code! gcc 2.95.1 compiled under UAE JIT for Linux!?
  1009.         wheelwidth = glob->screenres.y;
  1010.     wheelwidth *= wheelheight;
  1011.     wheelwidth /= glob->screenres.x;
  1012.     #else
  1013.     wheelwidth = wheelheight * glob->screenres.y / glob->screenres.x;
  1014.     #endif
  1015.     #endif
  1016.  
  1017.     if( ( scrwidth - winwidth > wheelwidth + 8 ) &&
  1018.           ( scrheight > 200 ) )
  1019.     {
  1020.         wheeloff = wheelwidth + 8;
  1021.         winwidth += wheeloff;
  1022.     }
  1023.     else
  1024.     {
  1025.         glob->dowheel = FALSE;
  1026.     }
  1027.  
  1028.     } /* if( glob->dowheel && glob->screenres.x && glob->screenres.y && ColorWheelBase && GradientSliderBase ) */
  1029.     else
  1030.     {
  1031.     glob->dowheel = FALSE;
  1032.     }
  1033. #endif
  1034.  
  1035.  
  1036.     rtSpread (gadpos, gadlen, width1, leftoff + wheeloff + 25, winwidth - rightoff, 3);
  1037.     rtSpread (gadpos + 3, gadlen + 3, width2, leftoff, winwidth - rightoff, 3);
  1038.  
  1039.  
  1040.     gad = (struct Gadget *)CreateContext (&glob->buttoninfo.glist);
  1041.     img = &glob->labelimages;
  1042.     ng.ng_Flags = 0;
  1043.     ng.ng_VisualInfo = glob->visinfo;
  1044.     ng.ng_TextAttr = &glob->font;
  1045.  
  1046.     str = GetStr (glob->catalog, MSG_PALETTE_COLORS);
  1047.     glob->palettekey = KeyFromStr (str, '_');
  1048.  
  1049.     i = leftoff + 25 + ( winwidth - ( leftoff + rightoff + 25 ) -
  1050.         StrWidth_noloc( &glob->itxt, str ) ) / 2;
  1051.  
  1052. #ifdef COLORWHEEL
  1053.     if( i < wheeloff )
  1054.     {
  1055.     i = wheeloff;
  1056.     }
  1057. #endif
  1058.  
  1059.     img = my_CreateGadgetLabelImage (img, &ng, str, i, top, HIGHLIGHTTEXTPEN);
  1060.     top += glob->fontheight + 1 + spacing / 2;
  1061.  
  1062.     InitNewGadget (&ng, leftoff + wheeloff + 25, top, winwidth - ( wheeloff + leftoff + rightoff + 25),
  1063.                         val, NULL, PALETTE_ID);
  1064.  
  1065.     gad = glob->palgad = myCreateGadget (PALETTE_KIND, gad, &ng,
  1066.         GTPA_Depth, (IPTR)glob->coldepth,
  1067.         GTPA_IndicatorWidth, 38,
  1068.         GTPA_Color, (IPTR)glob->color, TAG_END);
  1069.         
  1070.     if (glob->os30) top += gad->Height + spacing;
  1071.     else top += val + spacing;
  1072.  
  1073.     buttonheight = glob->fontheight + 6;
  1074.  
  1075.     for (i = 0; i < 3; i++)
  1076.     {
  1077.     InitNewGadget (&ng, gadpos[i], top, gadlen[i],
  1078.             buttonheight, string[i], COPY_ID + i);
  1079.             
  1080.     gad = my_CreateButtonGadget (gad, '_', &ng);
  1081.     }
  1082.     
  1083.     top += buttonheight + spacing;
  1084.  
  1085.     ng.ng_Flags |= NG_HIGHLABEL;
  1086.  
  1087.     maxwidth = 0;
  1088.     
  1089.     for (i = 0; i < 3; i++)
  1090.     {
  1091.     string[i] = GetStr (glob->catalog, colstr[i]);
  1092.     glob->key[i] = KeyFromStr (string[i], '_');
  1093.     val = StrWidth_noloc (&glob->itxt, string[i]);
  1094.     if (val > maxwidth) maxwidth = val;
  1095.     }
  1096.     
  1097.     levelwidth = StrWidth_noloc (&glob->itxt, "000 ");
  1098.     maxwidth += levelwidth;
  1099.  
  1100.  
  1101.     for (i = 0; i < 3; i++)
  1102.     {
  1103.  
  1104.     val = leftoff + wheeloff + 2 + maxwidth + 8;
  1105.     InitNewGadget (&ng, val, top, winwidth - val - rightoff,
  1106.                 glob->fontheight + 6, NULL, RED_ID + i);
  1107.  
  1108.     glob->colgad[i] = gad = myCreateGadget (SLIDER_KIND, gad, &ng,
  1109.         GTSL_LevelFormat, "%3ld",
  1110.         GTSL_LevelPlace, PLACETEXT_LEFT,
  1111.         GTSL_MaxLevelLen, 3, GA_RelVerify, TRUE, GA_Immediate, TRUE,
  1112.         GTSL_Level, glob->cols[i],
  1113.         GTSL_Max, glob->maxcolval[i],
  1114.         ((GfxBase->LibNode.lib_Version >= 40) ? GTSL_Justification : TAG_IGNORE), GTJ_RIGHT,
  1115.         GTSL_MaxPixelLen, levelwidth,
  1116.         TAG_END);
  1117.  
  1118.     img = my_CreateGadgetLabelImage (img, &ng, string[i],
  1119.             leftoff + wheeloff + 2, top + 2, HIGHLIGHTTEXTPEN);
  1120.     top += glob->fontheight + 6 + spacing / 2;
  1121.  
  1122.     }
  1123.  
  1124.     top += spacing / 2;
  1125.     ng.ng_Flags &= ~NG_HIGHLABEL;
  1126.  
  1127.  
  1128. #ifdef COLORWHEEL
  1129.     if( glob->dowheel )
  1130.     {
  1131.     int wheeltop = top - ( wheelheight + glob->fontheight + 3 + spacing * 2 );
  1132.  
  1133.     if( wheeltop < wheeltopoff )
  1134.     {
  1135.         top += wheeltopoff - wheeltop;
  1136.         wheeltop = wheeltopoff;
  1137.     }
  1138.  
  1139. #ifdef GRADIENT
  1140.  
  1141.     if( glob->fancywheel )
  1142.     {
  1143.  
  1144.         glob->numgradpens = LOWGRADPENS;
  1145.  
  1146.         if( glob->scr->ViewPort.ColorMap
  1147.         && glob->scr->ViewPort.ColorMap->PalExtra
  1148.         && ( glob->scr->ViewPort.ColorMap->PalExtra->pe_NFree > FREEFORHIGH ) )
  1149.         {
  1150.         glob->numgradpens = HIGHGRADPENS;
  1151.         }
  1152.  
  1153.         /* get the RGB components of active color */
  1154.         glob->wheel_rgb.cw_Red   = glob->cols[ RED_ID   ];
  1155.         glob->wheel_rgb.cw_Green = glob->cols[ GREEN_ID ];
  1156.         glob->wheel_rgb.cw_Blue  = glob->cols[ BLUE_ID  ];
  1157.  
  1158.         /* now convert the RGB values to HSB, and max out B component */
  1159.         ConvertRGBToHSB( &glob->wheel_rgb, &glob->wheel_hsb );
  1160.         glob->wheel_hsb.cw_Brightness = 0xffffffff;
  1161.  
  1162.  
  1163.         /* Set up colors for gradient slider */
  1164.         for( i = 0; i < glob->numgradpens; i++ )
  1165.         {
  1166.         glob->wheel_hsb.cw_Brightness = 0xffffffff
  1167.             - ( ( 0xffffffff / ( glob->numgradpens - 1 ) ) * ( ULONG ) i );
  1168.         ConvertHSBToRGB( &glob->wheel_hsb, &glob->wheel_rgb );
  1169.         glob->wheel_pens[ i ] = ObtainPen( glob->scr->ViewPort.ColorMap,
  1170.             -1, glob->wheel_rgb.cw_Red, glob->wheel_rgb.cw_Green,
  1171.             glob->wheel_rgb.cw_Blue, PEN_EXCLUSIVE );
  1172.  
  1173.         if( glob->wheel_pens[ i ] == (UWORD)~0 )
  1174.         {
  1175.             break;
  1176.         }
  1177.         }
  1178.  
  1179.  
  1180.         glob->wheel_pens[ i ] = ( UWORD ) ~0;
  1181.  
  1182.         if( i != glob->numgradpens )
  1183.         {
  1184.         for( i = 0; glob->wheel_pens[ i ] != (UWORD)~0; i++ )
  1185.         {
  1186.             ReleasePen( glob->scr->ViewPort.ColorMap, glob->wheel_pens[ i ] );
  1187.         }
  1188.  
  1189.         glob->numgradpens = 0;
  1190.         }
  1191.  
  1192.     } /* if( glob->fancywheel ) */
  1193. #endif
  1194.  
  1195.         {
  1196.         struct TagItem slider_tags[] =
  1197.         {
  1198.         {GA_ID                , SLIDER_ID                         },
  1199.         {GA_Top             , wheeltop + wheelheight + spacing    },
  1200.         {GA_Left            , leftoff                            },
  1201.         {GA_Width           , wheelwidth                        },
  1202.         {GA_Height          , glob->fontheight + 3              },
  1203. #ifdef GRADIENT
  1204.         {glob->numgradpens ?
  1205.          GRAD_PenArray :
  1206.          TAG_IGNORE         , (IPTR)glob->wheel_pens             },
  1207. #endif
  1208.         {GRAD_KnobPixels    , 8                                 },
  1209.         {PGA_Freedom        , LORIENT_HORIZ                     },
  1210.         {ICA_TARGET         , ICTARGET_IDCMP                    },
  1211.         {TAG_END                                                }
  1212.         };
  1213.             
  1214.         glob->wheel_slider = (struct Gadget *)NewObjectA(NULL, "gradientslider.gadget", slider_tags);
  1215.     
  1216.     }
  1217.     
  1218.     if( glob->wheel_slider )
  1219.     {
  1220.             struct TagItem wheel_tags[] =
  1221.         {
  1222.          {GA_Top                , wheeltop                  },
  1223.          {GA_Left               , leftoff                   },
  1224.          {GA_Width              , wheelwidth                },
  1225.          {GA_Height             , wheelheight                },
  1226.          {GA_ID                 , WHEEL_ID                  },
  1227.          {WHEEL_Screen            , (IPTR)glob->scr             },
  1228.          {glob->fancywheel ?
  1229.           TAG_IGNORE :
  1230.           WHEEL_MaxPens         , 0                         },
  1231.          {WHEEL_GradientSlider    , (IPTR)glob->wheel_slider  },
  1232. #ifdef _AROS
  1233. /* Need this, because without BevelBox AROS colorwheel gadget renders through mask
  1234. which because of bugs in gfx library functions (!?) does not work yet and instead
  1235. causes mem trashes/crashes/etc (in AmigaOS the AROS colorwheel gadget works fine
  1236. even without BevelBox, that is: with mask rendering) */
  1237.          {WHEEL_BevelBox        , TRUE                        },
  1238. #endif
  1239.          {GA_Previous            , (IPTR)glob->wheel_slider  },
  1240.          {ICA_TARGET            , ICTARGET_IDCMP            },
  1241.          {TAG_END                                           }
  1242.         };
  1243.         
  1244.         glob->wheel = (struct Gadget *)NewObjectA(NULL, "colorwheel.gadget", wheel_tags);
  1245.  
  1246.     }
  1247.         
  1248.     } /* if( glob->dowheel )*/
  1249. #endif
  1250.  
  1251.  
  1252.     for (i = 3; i < 6; i++)
  1253.     {
  1254.     InitNewGadget (&ng, gadpos[i], top, gadlen[i],
  1255.             buttonheight, string[i], COPY_ID + i);
  1256.             
  1257.     gad = my_CreateButtonGadget (gad, '_', &ng);
  1258.     }
  1259.     
  1260.     top += buttonheight + spacing;
  1261.  
  1262.     winheight = top + glob->scr->WBorBottom;
  1263.     glob->newpalwin.Height = winheight;
  1264.     glob->newpalwin.Width = winwidth;
  1265.     glob->newpalwin.IDCMPFlags = glob->shareidcmp ? 0 :
  1266.         SLIDERIDCMP|PALETTEIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY
  1267.         |IDCMP_REFRESHWINDOW|IDCMP_IDCMPUPDATE;
  1268.     glob->newpalwin.Flags = WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_ACTIVATE
  1269.                     |WFLG_SIMPLE_REFRESH|WFLG_RMBTRAP|WFLG_CLOSEGADGET;
  1270.     glob->newpalwin.DetailPen = glob->drinfo->dri_Pens[BACKGROUNDPEN];
  1271.     glob->newpalwin.BlockPen = glob->drinfo->dri_Pens[SHADOWPEN];
  1272.     glob->newpalwin.Title = title;
  1273.     glob->newpalwin.LeftEdge = glob->leftedge;
  1274.     glob->newpalwin.TopEdge = glob->topedge;
  1275.  
  1276.     reqpos = CheckReqPos (glob->reqpos, RTPREF_PALETTEREQ, &glob->newpalwin);
  1277.  
  1278.     if (reqpos == REQPOS_POINTER)
  1279.     {
  1280.     glob->newpalwin.LeftEdge = -winwidth / 2;
  1281.     glob->newpalwin.TopEdge = -winheight / 2;
  1282.     }
  1283.     
  1284.     rtSetReqPosition (reqpos, &glob->newpalwin, glob->scr, glob->prwin);
  1285.  
  1286.     ng.ng_LeftEdge = ng.ng_TopEdge = ng.ng_Width = ng.ng_Height = 0;
  1287.     ng.ng_GadgetText = NULL;
  1288.     gad = myCreateGadget (GENERIC_KIND, gad, &ng, TAG_END);
  1289.  
  1290.     if( gad )
  1291.     {
  1292.     gad->GadgetType |= GTYP_BOOLGADGET;
  1293.     gad->Flags |= GFLG_GADGIMAGE|GFLG_GADGHNONE;
  1294.     gad->GadgetRender = ( APTR ) glob->labelimages.NextImage;
  1295.     }
  1296.  
  1297.  
  1298.     glob->zoom[ 2 ] = glob->newpalwin.Width;
  1299.     glob->zoom[ 3 ] = glob->scr->WBorTop + glob->scr->Font->ta_YSize + 1;
  1300.  
  1301.     if( ( glob->dowheel && !glob->wheel ) || !img || !gad ||
  1302.       !(glob->palwin = OpenWindowBF( &glob->newpalwin,
  1303.       &glob->backfillhook, glob->drinfo->dri_Pens, NULL, glob->zoom, FALSE ) ) )
  1304.     {
  1305.     my_FreeGadgets( glob->buttoninfo.glist );
  1306.     glob->buttoninfo.glist = NULL;
  1307.     my_FreeLabelImages( &glob->labelimages );
  1308.     glob->labelimages.NextImage = NULL;
  1309.     DisposeObject( glob->wheel );
  1310.     glob->wheel = NULL;
  1311.     DisposeObject( glob->wheel_slider );
  1312.     glob->wheel_slider = NULL;
  1313.     return( 0 );
  1314.     }
  1315.  
  1316.     glob->buttoninfo.win = glob->palwin;
  1317.  
  1318.     if( glob->shareidcmp )
  1319.     {
  1320.     glob->palwin->UserPort = glob->prwin->UserPort;
  1321.     ModifyIDCMP( glob->palwin,
  1322.              SLIDERIDCMP | PALETTEIDCMP | BUTTONIDCMP | IDCMP_CLOSEWINDOW |
  1323.              IDCMP_RAWKEY | IDCMP_REFRESHWINDOW | IDCMP_IDCMPUPDATE );
  1324.     }
  1325.  
  1326. #ifdef COLORWHEEL
  1327.     if( glob->wheel )
  1328.     {
  1329.     AddGList( glob->palwin, glob->wheel_slider, -1, -1, NULL );
  1330.     RefreshGList( glob->wheel_slider, glob->palwin, NULL, -1 );
  1331.     }
  1332. #endif
  1333.  
  1334.     AddGList( glob->palwin, glob->buttoninfo.glist, -1, -1, NULL );
  1335.     RefreshGList( glob->buttoninfo.glist, glob->palwin, NULL, -1 );
  1336.     GT_RefreshWindow( glob->palwin, NULL );
  1337.     UpdateWheel( glob, glob->cols );
  1338.  
  1339.     return( 1 );
  1340. }
  1341.  
  1342. /****************************************************************************************/
  1343.